#include "threadPool.hpp"
#include "Task.hpp"
#include <iostream>
#include <ctime>
#include <unistd.h>
#include <pthread.h>

int main()
{
    srand((unsigned long)time(nullptr) ^ getpid()); // 设置随机数种子

    ThreadPool<Task>::getThreadPool()->run();   // 
    // std::cout << "tmp";

    while(true)
    {
        int x = rand() % 100 + 1;
        usleep(1000);
        int y = rand() % 30 + 1;
        Task t(x, y, [](int x, int y)->int{
            return x + y;
        });
        
        logMessage(DEBUG, "create task success: %d + %d = ?", x, y);
        logMessage(DEBUG, "create task success: %d + %d = ?", x, y);
        logMessage(DEBUG, "create task success: %d + %d = ?", x, y);
        logMessage(DEBUG, "create task success: %d + %d = ?", x, y);
    
        // 推送任务到线程池
        ThreadPool<Task>::getThreadPool()->pushTask(t);

        sleep(1);
    }

    return 0;
}